/**
 * Created by LeonTao on 17/3/23.
 */
///
$(document).ready(function () {
    $('.form').find('input, textarea').on('keyup blur focus', function (e) {

        var $this = $(this),
            label = $this.prev('label');

        if (e.type === 'keyup') {
            if ($this.val() === '') {
                label.removeClass('active highlight');
            } else {
                label.addClass('active highlight');
            }
        } else if (e.type === 'blur') {
            if ($this.val() === '') {
                label.removeClass('active highlight');
            } else {
                label.removeClass('highlight');
            }
        } else if (e.type === 'focus') {

            if ($this.val() === '') {
                label.removeClass('highlight');
            }
            else if ($this.val() !== '') {
                label.addClass('highlight');
            }
        }

    });

    $('.tab a').on('click', function (e) {

        e.preventDefault();

        $(this).parent().addClass('active');
        $(this).parent().siblings().removeClass('active');

        target = $(this).attr('href');

        $('.tab-content > div').not(target).hide();

        $(target).fadeIn(600);

    });


    //注册
    $('#signup').ajaxForm({
        beforeSubmit : function(formData, jqForm, options){
            console.log('--- signup ---', formData);

            // if (lv.validateForm() == false){
            //     return false;
            // } 	else{
            //     // append 'remember-me' option to formData to write local cookie //
            //     formData.push({name:'remember-me', value:$('.button-rememember-me-glyph').hasClass('glyphicon-ok')});
            //     return true;
            // }
        },
        success	: function(responseText, status, xhr, $form){
            if (status == 'success')
                window.location.href = '/home';
        },
        error : function(e){

        }
    });


    //登录  /index post
    $('#login').ajaxForm({
        beforeSubmit : function(formData, jqForm, options){
            console.log('--- login ---', formData);
            // formData.push({name:'type', value:'login'});
            return true;
        },
        success	: function(responseText, status, xhr, $form){
            console.log('--- responseText ---', responseText);
            console.log('--- status ---', status);
            if (status == 'success')
                window.location.href = '/home';
        },
        error : function(e){
            console.log('--- login error ---', status);
        }
    });





});